package com.zcmyth;

import java.util.regex.Pattern;
import java.util.regex.Matcher;

/*
http://download.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html
*/

class RegularExpression{
	
	static public void main(String []args){
		Pattern p = Pattern.compile("([a-z]+)d",Pattern.DOTALL);
		Matcher m = p.matcher("124asddda123asd");
		
		while(m.find())
		{
			System.out.println(m.group(1));
		}
	}
	
	static class MyPattern{
		private String pattern;
		
		public MyPattern(String pattern)
		{
			this.pattern = pattern;
		}
		
		public boolean match(String s)
		{
			return match(s,0,0);
		}
		
		private boolean match(String s,int pIndex, int sIndex)
		{
			if(pIndex == pattern.length())
				return true;
			if(s.length() == sIndex)
			{
				return false;
			}
			if(pattern.charAt(pIndex) == s.charAt(sIndex))
			{
				if(match(s,pIndex+1,sIndex+1))
					return true;
			}
			else if(pattern.charAt(pIndex) == '*')
			{
				if(match(s,pIndex+1,sIndex))
					return true;
				if(match(s,pIndex,sIndex+1))
					return true;
			}
			if(match(s,0,sIndex+1))
				return true;
			
			return false;
		}
	}
}